{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Typed dict input"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'6'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from typing import List\n",
    "from typing_extensions import TypedDict\n",
    "from langchain_core.runnables import RunnableLambda\n",
    "\n",
    "class Args(TypedDict):\n",
    "    a: int\n",
    "    b: List[int]\n",
    "\n",
    "def f(x: Args) -> str:\n",
    "    return str(x[\"a\"] * max(x[\"b\"]))\n",
    "\n",
    "runnable = RunnableLambda(f)\n",
    "as_tool = runnable.as_tool()\n",
    "as_tool.invoke({\"a\": 3, \"b\": [1, 2]})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### dict input, specifying schema via args_schema"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'6'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from typing import Any, Dict, List\n",
    "from langchain_core.pydantic_v1 import BaseModel, Field\n",
    "from langchain_core.runnables import RunnableLambda\n",
    "\n",
    "def f(x: Dict[str, Any]) -> str:\n",
    "    return str(x[\"a\"] * max(x[\"b\"]))\n",
    "\n",
    "class FSchema(BaseModel):\n",
    "    \"\"\"Apply a function to an integer and list of integers.\"\"\"\n",
    "\n",
    "    a: int = Field(..., description=\"Integer\")\n",
    "    b: List[int] = Field(..., description=\"List of ints\")\n",
    "\n",
    "runnable = RunnableLambda(f)\n",
    "as_tool = runnable.as_tool(FSchema)\n",
    "as_tool.invoke({\"a\": 3, \"b\": [1, 2]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'lc': 1,\n",
       " 'type': 'not_implemented',\n",
       " 'id': ['langchain_core', 'tools', 'StructuredTool'],\n",
       " 'repr': 'StructuredTool(name=\\'f\\', description=\"Takes {\\'title\\': \\'FSchema\\', \\'description\\': \\'Apply a function to an integer and list of integers.\\', \\'type\\': \\'object\\', \\'properties\\': {\\'a\\': {\\'title\\': \\'A\\', \\'description\\': \\'Integer\\', \\'type\\': \\'integer\\'}, \\'b\\': {\\'title\\': \\'B\\', \\'description\\': \\'List of ints\\', \\'type\\': \\'array\\', \\'items\\': {\\'type\\': \\'integer\\'}}}, \\'required\\': [\\'a\\', \\'b\\']}.\", args_schema=<class \\'__main__.FSchema\\'>, func=<function convert_runnable_to_tool.<locals>.invoke_wrapper at 0x0000011C7A054FE0>, coroutine=<function convert_runnable_to_tool.<locals>.ainvoke_wrapper at 0x0000011C7A055620>)',\n",
       " 'name': 'f',\n",
       " 'graph': {'nodes': [{'id': 0, 'type': 'schema', 'data': 'FSchema'},\n",
       "   {'id': 1,\n",
       "    'type': 'runnable',\n",
       "    'data': {'id': ['langchain_core', 'tools', 'StructuredTool'],\n",
       "     'name': 'f'}},\n",
       "   {'id': 2, 'type': 'schema', 'data': 'f_output'}],\n",
       "  'edges': [{'source': 0, 'target': 1}, {'source': 1, 'target': 2}]}}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "as_tool.to_json()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### dict input, specifying schema via arg_types:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'6'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from typing import Any, Dict, List\n",
    "from langchain_core.runnables import RunnableLambda\n",
    "\n",
    "def f(x: Dict[str, Any]) -> str:\n",
    "    return str(x[\"a\"] * max(x[\"b\"]))\n",
    "\n",
    "runnable = RunnableLambda(f)\n",
    "as_tool = runnable.as_tool(arg_types={\"a\": int, \"b\": List[int]})\n",
    "as_tool.invoke({\"a\": 3, \"b\": [1, 2]})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### String input:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'baz'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain_core.runnables import RunnableLambda\n",
    "\n",
    "def f(x: str) -> str:\n",
    "    return x + \"a\"\n",
    "\n",
    "def g(x: str) -> str:\n",
    "    return x + \"z\"\n",
    "\n",
    "runnable = RunnableLambda(f) | g\n",
    "as_tool = runnable.as_tool()\n",
    "as_tool.invoke(\"b\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### trim_intermediate_steps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
      "[]\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "\n",
      "\n",
      "\u001b[0mCall number: 1\n",
      "\u001b[36;1m\u001b[1;3m5\u001b[0m[(ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-bc8c69b2-9cdc-4d7f-b9a7-b2105abf559d', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915294594f763bd9cf0431180763d67979988a2'), 5)]\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "\n",
      "\n",
      "\u001b[0mCall number: 2\n",
      "\u001b[36;1m\u001b[1;3m6\u001b[0m[(ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-bc8c69b2-9cdc-4d7f-b9a7-b2105abf559d', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915294594f763bd9cf0431180763d67979988a2'), 5), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-1e704b1c-6702-4cda-84b2-663a5cacae00', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529464009942313024f74869e925023e8a1b1'), 6)]\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "\n",
      "\n",
      "\u001b[0mCall number: 3\n",
      "\u001b[36;1m\u001b[1;3m7\u001b[0m[(ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-bc8c69b2-9cdc-4d7f-b9a7-b2105abf559d', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915294594f763bd9cf0431180763d67979988a2'), 5), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-1e704b1c-6702-4cda-84b2-663a5cacae00', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529464009942313024f74869e925023e8a1b1'), 6), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-ee27923c-500e-4aef-a4fd-6f607b261477', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529478b38e15ab32d424c9a0ad96eb48377dc'), 7)]\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "\n",
      "\n",
      "\u001b[0mCall number: 4\n",
      "\u001b[36;1m\u001b[1;3m8\u001b[0m[(ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-bc8c69b2-9cdc-4d7f-b9a7-b2105abf559d', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915294594f763bd9cf0431180763d67979988a2'), 5), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-1e704b1c-6702-4cda-84b2-663a5cacae00', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529464009942313024f74869e925023e8a1b1'), 6), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-ee27923c-500e-4aef-a4fd-6f607b261477', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529478b38e15ab32d424c9a0ad96eb48377dc'), 7), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-10e66f52-687a-4631-b11a-50b2ed9cbb12', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529486a26da4c2637435887bdea6b7f055e3c'), 8)]\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "\n",
      "\n",
      "\u001b[0mCall number: 5\n",
      "\u001b[36;1m\u001b[1;3m9\u001b[0m[(ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-bc8c69b2-9cdc-4d7f-b9a7-b2105abf559d', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915294594f763bd9cf0431180763d67979988a2'), 5), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-1e704b1c-6702-4cda-84b2-663a5cacae00', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529464009942313024f74869e925023e8a1b1'), 6), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-ee27923c-500e-4aef-a4fd-6f607b261477', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529478b38e15ab32d424c9a0ad96eb48377dc'), 7), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-10e66f52-687a-4631-b11a-50b2ed9cbb12', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529486a26da4c2637435887bdea6b7f055e3c'), 8), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-f8c93ce2-7558-4873-b1e1-130a947cc619', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152949eea54219f4c148f0b7e4e80b38604822'), 9)]\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "\n",
      "\n",
      "\u001b[0mCall number: 6\n",
      "\u001b[36;1m\u001b[1;3m10\u001b[0m[(ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-bc8c69b2-9cdc-4d7f-b9a7-b2105abf559d', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915294594f763bd9cf0431180763d67979988a2'), 5), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-1e704b1c-6702-4cda-84b2-663a5cacae00', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529464009942313024f74869e925023e8a1b1'), 6), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-ee27923c-500e-4aef-a4fd-6f607b261477', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529478b38e15ab32d424c9a0ad96eb48377dc'), 7), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-10e66f52-687a-4631-b11a-50b2ed9cbb12', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529486a26da4c2637435887bdea6b7f055e3c'), 8), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-f8c93ce2-7558-4873-b1e1-130a947cc619', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152949eea54219f4c148f0b7e4e80b38604822'), 9), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-0e614aef-246b-4641-ae9a-de49e1677657', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529496ed45ee036b7416c9c8147aa0ed4d637'), 10)]\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "\n",
      "\n",
      "\u001b[0mCall number: 7\n",
      "\u001b[36;1m\u001b[1;3m11\u001b[0m[(ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-bc8c69b2-9cdc-4d7f-b9a7-b2105abf559d', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915294594f763bd9cf0431180763d67979988a2'), 5), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-1e704b1c-6702-4cda-84b2-663a5cacae00', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529464009942313024f74869e925023e8a1b1'), 6), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-ee27923c-500e-4aef-a4fd-6f607b261477', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529478b38e15ab32d424c9a0ad96eb48377dc'), 7), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-10e66f52-687a-4631-b11a-50b2ed9cbb12', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529486a26da4c2637435887bdea6b7f055e3c'), 8), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-f8c93ce2-7558-4873-b1e1-130a947cc619', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152949eea54219f4c148f0b7e4e80b38604822'), 9), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-0e614aef-246b-4641-ae9a-de49e1677657', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529496ed45ee036b7416c9c8147aa0ed4d637'), 10), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-09b8aaab-def5-441a-913b-a95062ca6e8e', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915295062f9416624cc4e51b55eab2450ed963e'), 11)]\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "\n",
      "\n",
      "\u001b[0mCall number: 8\n",
      "\u001b[36;1m\u001b[1;3m12\u001b[0m[(ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-bc8c69b2-9cdc-4d7f-b9a7-b2105abf559d', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915294594f763bd9cf0431180763d67979988a2'), 5), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-1e704b1c-6702-4cda-84b2-663a5cacae00', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529464009942313024f74869e925023e8a1b1'), 6), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-ee27923c-500e-4aef-a4fd-6f607b261477', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529478b38e15ab32d424c9a0ad96eb48377dc'), 7), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-10e66f52-687a-4631-b11a-50b2ed9cbb12', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529486a26da4c2637435887bdea6b7f055e3c'), 8), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-f8c93ce2-7558-4873-b1e1-130a947cc619', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152949eea54219f4c148f0b7e4e80b38604822'), 9), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-0e614aef-246b-4641-ae9a-de49e1677657', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529496ed45ee036b7416c9c8147aa0ed4d637'), 10), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-09b8aaab-def5-441a-913b-a95062ca6e8e', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915295062f9416624cc4e51b55eab2450ed963e'), 11), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-3e57cb2e-a60a-4173-8de1-e4fd8d531c96', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5'), 12)]\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "responded: directly using the function\n",
      "\n",
      "\u001b[0mCall number: 9\n",
      "\u001b[36;1m\u001b[1;3m13\u001b[0m[(ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-bc8c69b2-9cdc-4d7f-b9a7-b2105abf559d', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915294594f763bd9cf0431180763d67979988a2'), 5), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-1e704b1c-6702-4cda-84b2-663a5cacae00', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529464009942313024f74869e925023e8a1b1'), 6), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-ee27923c-500e-4aef-a4fd-6f607b261477', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529478b38e15ab32d424c9a0ad96eb48377dc'), 7), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-10e66f52-687a-4631-b11a-50b2ed9cbb12', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529486a26da4c2637435887bdea6b7f055e3c'), 8), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-f8c93ce2-7558-4873-b1e1-130a947cc619', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152949eea54219f4c148f0b7e4e80b38604822'), 9), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-0e614aef-246b-4641-ae9a-de49e1677657', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529496ed45ee036b7416c9c8147aa0ed4d637'), 10), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-09b8aaab-def5-441a-913b-a95062ca6e8e', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915295062f9416624cc4e51b55eab2450ed963e'), 11), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-3e57cb2e-a60a-4173-8de1-e4fd8d531c96', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5'), 12), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\nresponded: directly using the function\\n\\n\", message_log=[AIMessageChunk(content='directly using the function', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-6c095120-57ab-452c-912f-7a7057df373c', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529527df456a6ff084833b3e8eaf59b42d360'), 13)]\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "\n",
      "\n",
      "\u001b[0mCall number: 10\n",
      "\u001b[36;1m\u001b[1;3m14\u001b[0m[(ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-bc8c69b2-9cdc-4d7f-b9a7-b2105abf559d', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915294594f763bd9cf0431180763d67979988a2'), 5), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-1e704b1c-6702-4cda-84b2-663a5cacae00', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529464009942313024f74869e925023e8a1b1'), 6), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-ee27923c-500e-4aef-a4fd-6f607b261477', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529478b38e15ab32d424c9a0ad96eb48377dc'), 7), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-10e66f52-687a-4631-b11a-50b2ed9cbb12', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529486a26da4c2637435887bdea6b7f055e3c'), 8), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-f8c93ce2-7558-4873-b1e1-130a947cc619', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152949eea54219f4c148f0b7e4e80b38604822'), 9), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-0e614aef-246b-4641-ae9a-de49e1677657', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529496ed45ee036b7416c9c8147aa0ed4d637'), 10), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-09b8aaab-def5-441a-913b-a95062ca6e8e', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915295062f9416624cc4e51b55eab2450ed963e'), 11), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-3e57cb2e-a60a-4173-8de1-e4fd8d531c96', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5'), 12), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\nresponded: directly using the function\\n\\n\", message_log=[AIMessageChunk(content='directly using the function', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-6c095120-57ab-452c-912f-7a7057df373c', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529527df456a6ff084833b3e8eaf59b42d360'), 13), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-5323c295-2f1d-4d19-9120-1b5c7440fbb3', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529537c729c5c4acc4ca1aeef0601da5373b1'), 14)]\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "\n",
      "\n",
      "\u001b[0mCall number: 11\n",
      "\u001b[36;1m\u001b[1;3m15\u001b[0m[(ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-bc8c69b2-9cdc-4d7f-b9a7-b2105abf559d', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915294594f763bd9cf0431180763d67979988a2'), 5), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-1e704b1c-6702-4cda-84b2-663a5cacae00', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529464009942313024f74869e925023e8a1b1'), 6), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-ee27923c-500e-4aef-a4fd-6f607b261477', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529478b38e15ab32d424c9a0ad96eb48377dc'), 7), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-10e66f52-687a-4631-b11a-50b2ed9cbb12', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529486a26da4c2637435887bdea6b7f055e3c'), 8), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-f8c93ce2-7558-4873-b1e1-130a947cc619', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152949eea54219f4c148f0b7e4e80b38604822'), 9), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-0e614aef-246b-4641-ae9a-de49e1677657', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529496ed45ee036b7416c9c8147aa0ed4d637'), 10), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-09b8aaab-def5-441a-913b-a95062ca6e8e', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915295062f9416624cc4e51b55eab2450ed963e'), 11), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-3e57cb2e-a60a-4173-8de1-e4fd8d531c96', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5'), 12), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\nresponded: directly using the function\\n\\n\", message_log=[AIMessageChunk(content='directly using the function', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-6c095120-57ab-452c-912f-7a7057df373c', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529527df456a6ff084833b3e8eaf59b42d360'), 13), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-5323c295-2f1d-4d19-9120-1b5c7440fbb3', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529537c729c5c4acc4ca1aeef0601da5373b1'), 14), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152954e389f06a67a34d7994501c7ff5a8da37', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-9b383831-26ce-462a-9348-b24d6d4c6806', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152954e389f06a67a34d7994501c7ff5a8da37', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152954e389f06a67a34d7994501c7ff5a8da37', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152954e389f06a67a34d7994501c7ff5a8da37'), 15)]\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "\n",
      "\n",
      "\u001b[0mCall number: 12\n",
      "\u001b[36;1m\u001b[1;3m16\u001b[0m[(ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-bc8c69b2-9cdc-4d7f-b9a7-b2105abf559d', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915294594f763bd9cf0431180763d67979988a2'), 5), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-1e704b1c-6702-4cda-84b2-663a5cacae00', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529464009942313024f74869e925023e8a1b1'), 6), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-ee27923c-500e-4aef-a4fd-6f607b261477', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529478b38e15ab32d424c9a0ad96eb48377dc'), 7), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-10e66f52-687a-4631-b11a-50b2ed9cbb12', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529486a26da4c2637435887bdea6b7f055e3c'), 8), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-f8c93ce2-7558-4873-b1e1-130a947cc619', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152949eea54219f4c148f0b7e4e80b38604822'), 9), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-0e614aef-246b-4641-ae9a-de49e1677657', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529496ed45ee036b7416c9c8147aa0ed4d637'), 10), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-09b8aaab-def5-441a-913b-a95062ca6e8e', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915295062f9416624cc4e51b55eab2450ed963e'), 11), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-3e57cb2e-a60a-4173-8de1-e4fd8d531c96', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5'), 12), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\nresponded: directly using the function\\n\\n\", message_log=[AIMessageChunk(content='directly using the function', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-6c095120-57ab-452c-912f-7a7057df373c', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529527df456a6ff084833b3e8eaf59b42d360'), 13), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-5323c295-2f1d-4d19-9120-1b5c7440fbb3', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529537c729c5c4acc4ca1aeef0601da5373b1'), 14), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152954e389f06a67a34d7994501c7ff5a8da37', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-9b383831-26ce-462a-9348-b24d6d4c6806', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152954e389f06a67a34d7994501c7ff5a8da37', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152954e389f06a67a34d7994501c7ff5a8da37', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152954e389f06a67a34d7994501c7ff5a8da37'), 15), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152955d342b6cde912463ab2155840977f9e8f', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-5f2d2c06-2f50-4a8e-a6ff-5b69fe324373', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152955d342b6cde912463ab2155840977f9e8f', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152955d342b6cde912463ab2155840977f9e8f', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152955d342b6cde912463ab2155840977f9e8f'), 16)]\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "\n",
      "\n",
      "\u001b[0mCall number: 13\n",
      "\u001b[36;1m\u001b[1;3m17\u001b[0m[(ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-bc8c69b2-9cdc-4d7f-b9a7-b2105abf559d', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915294594f763bd9cf0431180763d67979988a2'), 5), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-1e704b1c-6702-4cda-84b2-663a5cacae00', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529464009942313024f74869e925023e8a1b1'), 6), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-ee27923c-500e-4aef-a4fd-6f607b261477', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529478b38e15ab32d424c9a0ad96eb48377dc'), 7), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-10e66f52-687a-4631-b11a-50b2ed9cbb12', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529486a26da4c2637435887bdea6b7f055e3c'), 8), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-f8c93ce2-7558-4873-b1e1-130a947cc619', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152949eea54219f4c148f0b7e4e80b38604822'), 9), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-0e614aef-246b-4641-ae9a-de49e1677657', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529496ed45ee036b7416c9c8147aa0ed4d637'), 10), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-09b8aaab-def5-441a-913b-a95062ca6e8e', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915295062f9416624cc4e51b55eab2450ed963e'), 11), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-3e57cb2e-a60a-4173-8de1-e4fd8d531c96', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5'), 12), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\nresponded: directly using the function\\n\\n\", message_log=[AIMessageChunk(content='directly using the function', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-6c095120-57ab-452c-912f-7a7057df373c', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529527df456a6ff084833b3e8eaf59b42d360'), 13), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-5323c295-2f1d-4d19-9120-1b5c7440fbb3', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529537c729c5c4acc4ca1aeef0601da5373b1'), 14), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152954e389f06a67a34d7994501c7ff5a8da37', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-9b383831-26ce-462a-9348-b24d6d4c6806', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152954e389f06a67a34d7994501c7ff5a8da37', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152954e389f06a67a34d7994501c7ff5a8da37', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152954e389f06a67a34d7994501c7ff5a8da37'), 15), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152955d342b6cde912463ab2155840977f9e8f', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-5f2d2c06-2f50-4a8e-a6ff-5b69fe324373', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152955d342b6cde912463ab2155840977f9e8f', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152955d342b6cde912463ab2155840977f9e8f', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152955d342b6cde912463ab2155840977f9e8f'), 16), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529569b1f54099146495fbe88b9d76be97d44', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-057689e8-e75e-4b63-b9c3-40dbfce5fab8', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529569b1f54099146495fbe88b9d76be97d44', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529569b1f54099146495fbe88b9d76be97d44', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529569b1f54099146495fbe88b9d76be97d44'), 17)]\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "\n",
      "\n",
      "\u001b[0mCall number: 14\n",
      "\u001b[36;1m\u001b[1;3m18\u001b[0m[(ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-bc8c69b2-9cdc-4d7f-b9a7-b2105abf559d', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915294594f763bd9cf0431180763d67979988a2', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915294594f763bd9cf0431180763d67979988a2'), 5), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-1e704b1c-6702-4cda-84b2-663a5cacae00', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529464009942313024f74869e925023e8a1b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529464009942313024f74869e925023e8a1b1'), 6), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-ee27923c-500e-4aef-a4fd-6f607b261477', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529478b38e15ab32d424c9a0ad96eb48377dc', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529478b38e15ab32d424c9a0ad96eb48377dc'), 7), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-10e66f52-687a-4631-b11a-50b2ed9cbb12', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529486a26da4c2637435887bdea6b7f055e3c', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529486a26da4c2637435887bdea6b7f055e3c'), 8), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-f8c93ce2-7558-4873-b1e1-130a947cc619', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152949eea54219f4c148f0b7e4e80b38604822', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152949eea54219f4c148f0b7e4e80b38604822'), 9), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-0e614aef-246b-4641-ae9a-de49e1677657', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529496ed45ee036b7416c9c8147aa0ed4d637', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529496ed45ee036b7416c9c8147aa0ed4d637'), 10), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-09b8aaab-def5-441a-913b-a95062ca6e8e', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_2024071915295062f9416624cc4e51b55eab2450ed963e', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_2024071915295062f9416624cc4e51b55eab2450ed963e'), 11), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-3e57cb2e-a60a-4173-8de1-e4fd8d531c96', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152951da742595c5fd4b1cbc5e460d1e96fcb5'), 12), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\nresponded: directly using the function\\n\\n\", message_log=[AIMessageChunk(content='directly using the function', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-6c095120-57ab-452c-912f-7a7057df373c', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529527df456a6ff084833b3e8eaf59b42d360', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529527df456a6ff084833b3e8eaf59b42d360'), 13), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-5323c295-2f1d-4d19-9120-1b5c7440fbb3', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529537c729c5c4acc4ca1aeef0601da5373b1', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529537c729c5c4acc4ca1aeef0601da5373b1'), 14), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152954e389f06a67a34d7994501c7ff5a8da37', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-9b383831-26ce-462a-9348-b24d6d4c6806', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152954e389f06a67a34d7994501c7ff5a8da37', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152954e389f06a67a34d7994501c7ff5a8da37', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152954e389f06a67a34d7994501c7ff5a8da37'), 15), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152955d342b6cde912463ab2155840977f9e8f', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-5f2d2c06-2f50-4a8e-a6ff-5b69fe324373', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152955d342b6cde912463ab2155840977f9e8f', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152955d342b6cde912463ab2155840977f9e8f', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152955d342b6cde912463ab2155840977f9e8f'), 16), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_202407191529569b1f54099146495fbe88b9d76be97d44', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-057689e8-e75e-4b63-b9c3-40dbfce5fab8', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_202407191529569b1f54099146495fbe88b9d76be97d44', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_202407191529569b1f54099146495fbe88b9d76be97d44', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_202407191529569b1f54099146495fbe88b9d76be97d44'), 17), (ToolAgentAction(tool='magic_function', tool_input={'input': 3}, log=\"\\nInvoking: `magic_function` with `{'input': 3}`\\n\\n\\n\", message_log=[AIMessageChunk(content='', additional_kwargs={'tool_calls': [{'index': 0, 'id': 'call_20240719152957345258ceb11842d5834b61e6fd3346fd', 'function': {'arguments': '{\"input\":3}', 'name': 'magic_function'}, 'type': 'function'}]}, response_metadata={'finish_reason': 'tool_callstool_calls', 'model_name': 'glm-4glm-4'}, id='run-eaa6e8a0-cf34-4084-9672-ae8da4a149a1', tool_calls=[{'name': 'magic_function', 'args': {'input': 3}, 'id': 'call_20240719152957345258ceb11842d5834b61e6fd3346fd', 'type': 'tool_call'}], tool_call_chunks=[{'name': 'magic_function', 'args': '{\"input\":3}', 'id': 'call_20240719152957345258ceb11842d5834b61e6fd3346fd', 'index': 0, 'type': 'tool_call_chunk'}])], tool_call_id='call_20240719152957345258ceb11842d5834b61e6fd3346fd'), 18)]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Stopping agent prematurely due to triggering stop condition\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 3}`\n",
      "\n",
      "\n",
      "\u001b[0mCall number: 15\n",
      "\u001b[36;1m\u001b[1;3m19\u001b[0m\u001b[32;1m\u001b[1;3m\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "from langchain.agents import AgentExecutor, create_tool_calling_agent\n",
    "from langchain_core.prompts import ChatPromptTemplate\n",
    "from langchain_core.tools import tool\n",
    "from ChatGLM_new import zhipu_llm\n",
    "\n",
    "\n",
    "prompt = ChatPromptTemplate.from_messages(\n",
    "    [\n",
    "        (\"system\", \"You are a helpful assistant.\"),\n",
    "        (\"human\", \"{input}\"),\n",
    "        # Placeholders fill up a **list** of messages\n",
    "        (\"placeholder\", \"{agent_scratchpad}\"),\n",
    "    ]\n",
    ")\n",
    "\n",
    "\n",
    "magic_step_num = 1\n",
    "\n",
    "\n",
    "@tool\n",
    "def magic_function(input: int) -> int:\n",
    "    \"\"\"Applies a magic function to an input.\"\"\"\n",
    "    global magic_step_num\n",
    "    print(f\"Call number: {magic_step_num}\")\n",
    "    magic_step_num += 1\n",
    "    return input + magic_step_num\n",
    "\n",
    "\n",
    "tools = [magic_function]\n",
    "\n",
    "agent = create_tool_calling_agent(zhipu_llm, tools, prompt=prompt)\n",
    "\n",
    "\n",
    "def trim_steps(steps: list):\n",
    "    print(steps)\n",
    "    # Let's give the agent amnesia\n",
    "    return []\n",
    "\n",
    "\n",
    "agent_executor = AgentExecutor(\n",
    "    agent=agent, tools=tools, trim_intermediate_steps=trim_steps,verbose=True\n",
    ")\n",
    "# agent_executor = AgentExecutor(\n",
    "#     agent=agent, tools=tools, verbose=True\n",
    "# )\n",
    "\n",
    "\n",
    "\n",
    "query = \"Call the magic function 4 times in sequence with the value 3. You cannot call it multiple times at once.\"\n",
    "\n",
    "res = agent_executor.stream({\"input\": query})\n",
    "\n",
    "for step in agent_executor.stream({\"input\": query}):\n",
    "    pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### early_stopping_method"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 1}`\n",
      "\n",
      "\n",
      "\u001b[0m\u001b[36;1m\u001b[1;3mSorry there was an error, please try again.\u001b[0m\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': 1}`\n",
      "\n",
      "\n",
      "\u001b[0m\u001b[36;1m\u001b[1;3mSorry there was an error, please try again.\u001b[0m\u001b[32;1m\u001b[1;3m\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n",
      "Output with early_stopping_method='force':\n",
      "Agent stopped due to max iterations.\n"
     ]
    }
   ],
   "source": [
    "from langchain.agents import AgentExecutor, create_tool_calling_agent\n",
    "from langchain_core.prompts import ChatPromptTemplate\n",
    "from langchain_core.tools import tool\n",
    "from ChatGLM_new import zhipu_llm\n",
    "\n",
    "query = \"调用100次magic_function输入参数1\"\n",
    "prompt = ChatPromptTemplate.from_messages(\n",
    "    [\n",
    "        (\"system\", \"You are a helpful assistant.\"),\n",
    "        (\"human\", \"{input}\"),\n",
    "        # Placeholders fill up a **list** of messages\n",
    "        (\"placeholder\", \"{agent_scratchpad}\"),\n",
    "    ]\n",
    ")\n",
    "\n",
    "\n",
    "@tool\n",
    "def magic_function(input: int) -> int:\n",
    "    \"\"\"Applies a magic function to an input.\"\"\"\n",
    "    return \"Sorry there was an error, please try again.\"\n",
    "\n",
    "\n",
    "tools = [magic_function]\n",
    "\n",
    "agent = create_tool_calling_agent(zhipu_llm, tools, prompt=prompt)\n",
    "agent_executor = AgentExecutor(\n",
    "    agent=agent, tools=tools, early_stopping_method=\"force\", max_iterations=2,verbose=True\n",
    ")\n",
    "\n",
    "result = agent_executor.invoke({\"input\": query})\n",
    "print(\"Output with early_stopping_method='force':\")\n",
    "print(result[\"output\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### max_execution_time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': '3'}`\n",
      "\n",
      "\n",
      "\u001b[0m\u001b[36;1m\u001b[1;3mSorry, there was an error. Please try again.\u001b[0m\u001b[32;1m\u001b[1;3m\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'input': 'what is the value of magic_function(3)?',\n",
       " 'output': 'Agent stopped due to max iterations.'}"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "from ChatGLM_new import tongyi_llm\n",
    "\n",
    "query = \"what is the value of magic_function(3)?\"\n",
    "\n",
    "@tool\n",
    "def magic_function(input: str) -> str:\n",
    "    \"\"\"Applies a magic function to an input.\"\"\"\n",
    "    time.sleep(2.5)\n",
    "    return \"Sorry, there was an error. Please try again.\"\n",
    "\n",
    "\n",
    "tools = [magic_function]\n",
    "\n",
    "agent = create_tool_calling_agent(zhipu_llm, tools, prompt)\n",
    "agent_executor = AgentExecutor(\n",
    "    agent=agent,\n",
    "    tools=tools,\n",
    "    max_execution_time=1,\n",
    "    verbose=True,\n",
    ")\n",
    "\n",
    "agent_executor.invoke({\"input\": query})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### max_iterations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
      "\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': '3'}`\n",
      "\n",
      "\n",
      "\u001b[0m\u001b[36;1m\u001b[1;3mSorry, there was an error. Please try again.\u001b[0m\u001b[32;1m\u001b[1;3m\n",
      "Invoking: `magic_function` with `{'input': '3'}`\n",
      "\n",
      "\n",
      "\u001b[0m\u001b[36;1m\u001b[1;3mSorry, there was an error. Please try again.\u001b[0m\u001b[32;1m\u001b[1;3mSe ha producido un error al intentar aplicar la función mágica. Inténtalo de nuevo.\u001b[0m\n",
      "\n",
      "\u001b[1m> Finished chain.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'input': 'what is the value of magic_function(3)?',\n",
       " 'output': 'Se ha producido un error al intentar aplicar la función mágica. Inténtalo de nuevo.'}"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@tool\n",
    "def magic_function(input: str) -> str:\n",
    "    \"\"\"Applies a magic function to an input.\"\"\"\n",
    "    return \"Sorry, there was an error. Please try again.\"\n",
    "\n",
    "\n",
    "tools = [magic_function]\n",
    "\n",
    "prompt = ChatPromptTemplate.from_messages(\n",
    "    [\n",
    "        (\"system\", \"You are a helpful assistant. Respond only in Spanish.\"),\n",
    "        (\"human\", \"{input}\"),\n",
    "        # Placeholders fill up a **list** of messages\n",
    "        (\"placeholder\", \"{agent_scratchpad}\"),\n",
    "    ]\n",
    ")\n",
    "\n",
    "agent = create_tool_calling_agent(zhipu_llm, tools, prompt)\n",
    "agent_executor = AgentExecutor(\n",
    "    agent=agent,\n",
    "    tools=tools,\n",
    "    verbose=True,\n",
    "    max_iterations=3,\n",
    ")\n",
    "\n",
    "agent_executor.invoke({\"input\": query})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### placeholder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ChatPromptValue(messages=[SystemMessage(content='You are a helpful assistant. Respond only in Spanish.'), HumanMessage(content='What is the capital of France?'), HumanMessage(content='Hi!'), AIMessage(content='How can I assist you today?'), ToolMessage(content='工具输出', tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL', artifact='tool_output')])"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain_core.messages import (\n",
    "    AIMessage,\n",
    "    BaseMessage,\n",
    "    ToolMessage,\n",
    ")\n",
    "@tool\n",
    "def magic_function(input: str) -> str:\n",
    "    \"\"\"Applies a magic function to an input.\"\"\"\n",
    "    return \"Sorry, there was an error. Please try again.\"\n",
    "\n",
    "\n",
    "tool_message = ToolMessage(\n",
    "                content=\"工具输出\",\n",
    "                artifact=\"tool_output\",\n",
    "                tool_call_id='call_Jja7J89XsjrOLA5r!MEOW!SL',\n",
    "            )\n",
    "\n",
    "prompt = ChatPromptTemplate.from_messages(\n",
    "    [\n",
    "        (\"system\", \"You are a helpful assistant. Respond only in Spanish.\"),\n",
    "        (\"human\", \"{input}\"),\n",
    "        # Placeholders fill up a **list** of messages\n",
    "        (\"placeholder\", \"{agent_scratchpad}\"),\n",
    "    ]\n",
    ")\n",
    "prompt_value = prompt.invoke({\"input\": \"What is the capital of France?\",\"agent_scratchpad\": [(\"human\", \"Hi!\"),(\"ai\", \"How can I assist you today?\"),tool_message]})\n",
    "prompt_value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### MessagesPlaceholder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[SystemMessage(content='You are an AI assistant.'),\n",
       " HumanMessage(content='Hello!')]"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain_core.prompts import MessagesPlaceholder\n",
    "\n",
    "# history=[\n",
    "#                     (\"system\", \"You are an AI assistant.\"),\n",
    "#                     (\"human\", \"Hello!\"),\n",
    "#                 ]\n",
    "prompt = MessagesPlaceholder(\"history\")\n",
    "#prompt.format_messages() # raises KeyError\n",
    "\n",
    "prompt = MessagesPlaceholder(\"history\", optional=True)\n",
    "prompt.format_messages() # returns empty list []\n",
    "\n",
    "prompt.format_messages(\n",
    "    history=[\n",
    "        (\"system\", \"You are an AI assistant.\"),\n",
    "        (\"human\", \"Hello!\"),\n",
    "    ]\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### chat history"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ChatPromptValue(messages=[SystemMessage(content='You are a helpful assistant.'), HumanMessage(content=\"what's 5 + 2\"), AIMessage(content='5 + 2 is 7'), HumanMessage(content='now multiply that by 4')])"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder\n",
    "\n",
    "prompt = ChatPromptTemplate.from_messages(\n",
    "    [\n",
    "        (\"system\", \"You are a helpful assistant.\"),\n",
    "        MessagesPlaceholder(\"history\"),\n",
    "        (\"human\", \"{question}\")\n",
    "    ]\n",
    ")\n",
    "prompt.invoke(\n",
    "   {\n",
    "       \"history\": [(\"human\", \"what's 5 + 2\"), (\"ai\", \"5 + 2 is 7\")],\n",
    "       \"question\": \"now multiply that by 4\"\n",
    "   }\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### PromptTemplate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Say bar\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "StringPromptValue(text='Say bar')"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain_core.prompts import PromptTemplate\n",
    "\n",
    "# Instantiation using from_template (recommended)\n",
    "prompt = PromptTemplate.from_template(\"Say {foo}\")\n",
    "print(prompt.format(foo=\"bar\"))\n",
    "\n",
    "# Instantiation using initializer\n",
    "prompt = PromptTemplate(template=\"Say {foo}\")\n",
    "prompt.invoke({\"foo\": \"bar\"})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ChatPromptTemplate\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ChatPromptValue(messages=[SystemMessage(content='You are a helpful AI bot. Your name is Bob.'), HumanMessage(content='Hello, how are you doing?'), AIMessage(content=\"I'm doing well, thanks!\"), HumanMessage(content='What is your name?')])"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain_core.prompts import ChatPromptTemplate\n",
    "\n",
    "template = ChatPromptTemplate.from_messages([\n",
    "    (\"system\", \"You are a helpful AI bot. Your name is {name}.\"),\n",
    "    (\"human\", \"Hello, how are you doing?\"),\n",
    "    (\"ai\", \"I'm doing well, thanks!\"),\n",
    "    (\"human\", \"{user_input}\"),\n",
    "])\n",
    "\n",
    "prompt_value = template.invoke(\n",
    "    {\n",
    "        \"name\": \"Bob\",\n",
    "        \"user_input\": \"What is your name?\"\n",
    "    }\n",
    ")\n",
    "prompt_value"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Messages Placeholder"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ChatPromptValue(messages=[SystemMessage(content='You are a helpful AI bot.'), HumanMessage(content='Hi!'), AIMessage(content='How can I assist you today?'), HumanMessage(content='Can you make me an ice cream sundae?'), AIMessage(content='No.')])"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# In addition to Human/AI/Tool/Function messages,\n",
    "# you can initialize the template with a MessagesPlaceholder\n",
    "# either using the class directly or with the shorthand tuple syntax:\n",
    "\n",
    "template = ChatPromptTemplate.from_messages([\n",
    "    (\"system\", \"You are a helpful AI bot.\"),\n",
    "    # Means the template will receive an optional list of messages under\n",
    "    # the \"conversation\" key\n",
    "    (\"placeholder\", \"{conversation}\")\n",
    "    # Equivalently:\n",
    "    # MessagesPlaceholder(variable_name=\"conversation\", optional=True)\n",
    "])\n",
    "\n",
    "prompt_value = template.invoke(\n",
    "    {\n",
    "        \"conversation\": [\n",
    "            (\"human\", \"Hi!\"),\n",
    "            (\"ai\", \"How can I assist you today?\"),\n",
    "            (\"human\", \"Can you make me an ice cream sundae?\"),\n",
    "            (\"ai\", \"No.\")\n",
    "        ]\n",
    "    }\n",
    ")\n",
    "prompt_value"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
